$(function(){
    $(document).on('click', '.cb', function(){
        var flag = false;
        if($(this).is(':checked')){ flag = true; }
        var cbs = $(this).parent().find('input[type="checkbox"]');
        for(var i in cbs){ cbs[i].checked = flag; }
    });
});

//检查节点表单
function checkNode()
{
    var obj_node_name = $('#node_name');
    if($.trim(obj_node_name.val())==''){
        obj_node_name.css('background-color','#ffc');
        obj_node_name.next('span').html('<span class="color_0"> 节点名称不能为空</span>');
        obj_node_name.focus();
        return false;
    }else{
        obj_node_name.css('background-color','#fff');
        obj_node_name.next('span').html('');
    }

    var obj_m_c_a = $('#m_c_a');
    if($.trim(obj_m_c_a.val())==''){
        obj_m_c_a.css('background-color','#ffc');
        obj_m_c_a.next('span').html('<span class="color_0"> 节点地址不能为空</span>');
        obj_m_c_a.focus();
        return false;
    }else{
        obj_m_c_a.css('background-color','#fff');
        obj_m_c_a.next('span').html('');
    }

    return true;
}

//检查分组表单
function checkGroup()
{
    var obj_group_name = $('#group_name');
    if($.trim(obj_group_name.val())==''){
        obj_group_name.css('background-color','#ffc');
        obj_group_name.next('span').html('<font color=red> 分组名称不能为空</font>');
        obj_group_name.focus();
        return false;
    }else{
        obj_group_name.css('background-color','#fff');
        obj_group_name.next('span').html('');
    }
    return true;
}

//检查用户表单
function checkAdmin()
{
    var cb = $('input[name="hospital_ids[]"]');
    var hs = [];
    cb.each(function(index){
        if($(this).is(":checked")){
            hs.push($(this).val());
        }
    });
    if(hs.length < 1){
        redTip('请勾选所属医院');
        return false;
    }

    var obj_real_name = $('#real_name').val();
    if($.trim(obj_real_name)==''){
        redTip('姓名不能为空');
        return false;
    }

    var obj_cellphone = $('#cellphone').val();
    if($.trim(obj_cellphone) != ''){
        if( ! isMobile(obj_cellphone)){
            redTip('手机号码格式不正确');
            return false;
        }
    }

    var obj_email = $('#email').val();
    if($.trim(obj_email) != ''){
        if( ! isEmail(obj_email)){
            redTip('Email格式不正确');
            return false;
        }
    }

    if(obj_cellphone=='' && obj_email==''){
        redTip('Email或手机号码必须填一项');
        return false;
    }

    if($.trim($('#admin_group_id').val())=='-1'){
        redTip('请选择分组');
        return false;
    }
    return true;
}

//得到分组的权限
function getGroupAcl(group_id)
{
    $.ajax({
        url:'/admin/acl/ajax_get_nodes_checkbox',
        data:({'group_id':group_id}),
        dataType:'json',
        success:function(msg){
            $('.node_list').html($(msg.htm));
        }
    })
}